/**
 * Created by Administrator on 2022/8/21.
 */
/*class Animal {
    public String name = "阿黄";
    public int age = 2;

    public void eat() {
        System.out.println(name+"吃饭饭");
    }
}
//如果访问的成员变量子类中有，优先访问自己的成员变量
class Dog extends Animal {
    public String name = "多多";//与父类成员变量同名且同类型
    public String age = "1";//与父类成员变量同名不同类型
    public void call() {
        System.out.println(name+"汪汪");//子类中的name
        System.out.println(super.name+"汪汪");//加了super就是父类中的super

        System.out.println(age);//子类中的age
        System.out.println(super.age);//加了super就是父类中的super
    }
}
public class Test {
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.call();
    }

}*/

/*class Animal {
    public String name = "阿黄";

    public void eat() {
        System.out.println(name+"吃饭饭1");
    }
    public void call() {
        System.out.println(name+"在叫");
    }
}
class Dog extends Animal {
    //成员方法名一样、形参一样、返回类型一样，与父类的eat()造成了重写
    public void eat() {
        System.out.println(name+"吃饭饭2");
    }
    //成员方法名一样、形参不一样、返回类型一样，与父类的eat()造成了重载
    public void call(String c) {
        System.out.println(name+c);
    }
    public void print() {
        eat();//子类方法有的优先访问子类的
        super.eat();//加了super访问的就是父类的
        call();//无参，父类的call也是无参，访问父类
        call("汪汪汪");//有参，子类的call也有参，访问子类
    }

}
public class Test {
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.print();

    }

}*/


/*class Animal {
    public String name;
    public int age;

    public Animal(String name,int age){
        System.out.println("Animal");
    }
}

class Dog extends Animal {
    public Dog(){
        //super();//注意子类构造方法中默认会调用基类的无参构造方法：super(),但不会默认调用有参构造方法
        super("阿黄",2);
        System.out.println("dog");
    }
    public void call() {
        System.out.println(name+"汪汪");
    }
}
public class Test {
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.call();
    }
}*/


//再谈初始化
class Animal {
    public Animal(){
        System.out.println("Animal构造方法");
    }
    static {
        System.out.println("Animal静态代码块");
    }

    {
        System.out.println("Animal实例代码块");
    }
}

class Dog extends Animal {
    public Dog(){
        super();
        System.out.println("Dog构造方法");
    }
    static {
        System.out.println("Dog静态代码块");
    }

    {
        System.out.println("Dog实例代码块");
    }
}

class Cat extends Animal {
    public Cat(){
        super();
        System.out.println("Cat构造方法");
    }
    static {
        System.out.println("Cat静态代码块");
    }

    {
        System.out.println("Cat实例代码块");
    }
}
public class Test {
    public static void main(String[] args) {
        Dog dog = new Dog();
        System.out.println("-----------------");
        Cat cat = new Cat();

    }
}
